#include <iostream>
#include <algorithm >
using namespace std;
struct node{
	string name;
	string code;
	int a;
} p[100];
bool cmp(node x,node y){
	return x.a >y.a;
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>p[i].name >>p[i].code >>p[i].a;
	}
	sort(p,p+n,cmp);
	cout<<p[0].name <<" "<<p[0].code <<endl;
	cout<<p[n-1].name <<" "<<p[n-1].code <<endl;
	return 0;
}
